import redis

client = redis.Redis()
# # 一条数据
# client.lpush('list_python','python')
# client.rpush('list_python','life is short')
# # 多条数据
# # 法一
# client.lpush('list_python', 'first', 2, 4.0, '第四条')
# client.rpush('list_python', 'end', 22, 'apple', '张三')
# # 法二
# datas = ['one', 'two', 'three', 'four']
# client.lpush('list_python', *datas)
# client.rpush('list_python', *datas)
# 查看列表长度
# print(client.llen('list_python'))  # 10
# # 获取列表中一定索引范围的数据。
# print(client.lrange('list_python', 0, -1))
# # 使用for循环把数据展开。
# for data in client.lrange('list_python', 0, -1):
#     print(data.decode())
# 从左右侧弹出数据
# wordl = client.lpop('list_python').decode()  # three
# wordr = client.rpop('list_python').decode()  # four
# print(wordr)

# 修改数据
'''
one
python
life is short
one
two
three
'''
# client.lset(key,index,value)
client.lset('list_python', 3, 'four')
for data in client.lrange('list_python', 0, -1):
    print(data.decode())
'''
one
python
life is short
four
two
three
'''